package com.sky.mapper.user;

import com.sky.pojo.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    @Insert("insert into address_book (user_id, consignee, phone, sex, province_code, province_name, city_code, city_name, district_code, district_name, detail, label, is_default) " +
                    "values (#{userId}, #{consignee}, #{phone}, #{sex}, #{provinceCode}, #{provinceName},#{cityCode}, #{cityName}, #{districtCode}, #{districtName},#{detail},#{label},#{isDefault})")
    void insert(AddressBook addressBook);

    @Select("select * from address_book where user_id = #{userId}")
    List<AddressBook> selectAll(Long userId);

    @Select("select * from address_book where is_default = 1 and user_id = #{userId}")
    AddressBook selectDefaultAddresss(Long userId);


    @Update("update address_book set is_default = #{isDefault} where id =#{id}")
    void setDefault(Long id,Integer isDefault);

    @Select("select * from address_book where id = #{id}")
    AddressBook selectById(Long id);

    void update(AddressBook addressBook);

    @Delete("delete from address_book where id = #{id}")
    void deleteById(Long id);
}
